package com.heima.article.listener;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.heima.article.entity.ApArticle;
import com.heima.article.service.IApArticleService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
public class UpDownListener {
    @Autowired
    IApArticleService articleService;

    @KafkaListener(topics = {"${topic.upDownTopic}"})
    public void handleMsg(ConsumerRecord<String,String> record){
        String key = record.key();
        String value = record.value();
        //更新文章表的is_down
        LambdaUpdateWrapper<ApArticle> updateWrapper = new LambdaUpdateWrapper<>();

        updateWrapper.eq(ApArticle::getId,key);
        updateWrapper.set(ApArticle::getIsDown,value.equals("true")? false : true);
        articleService.update(updateWrapper);
    }
}
